package com.example.yuntiku.Servlet;

import com.alibaba.fastjson.JSON;
import com.example.yuntiku.Service.CurriculumService;
import com.example.yuntiku.entity.Curriculum;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "CurriculumTwoServlet", value = "/CurriculumTwoServlet")
public class CurriculumTwoServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String selectedOne = request.getParameter("one");
        if (selectedOne == null) {
            selectedOne = "2"; // 设置一个默认值，默认为2
        }
        CurriculumService curriculumService = new CurriculumService();
        List<Curriculum> list = curriculumService.two(Integer.parseInt(selectedOne));
        String jsonString = JSON.toJSONString(list);
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().println(jsonString);
    }
}